<%--
  - Author		:	이 영호
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8" %>
<%@ include file="./WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="./WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="./WEB-INF/pages/includes/doctype.jspf" %>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
				document.frm.text.focus();
			});
			
			function goAction(trObj){
				var addrNum = $(trObj).children().eq(0).html();
				var addr1 = $(trObj).children().eq(1).html();
				opener.setAddr(addrNum, addr1);
				window.close();
			}
			
			function getAddr(){
				var dong =  document.frm.text.value;
				if(dong.replace(/\s/g, '') == ""){
					alert("동이름을 입력하세요.");
				}else{
					$.ajax({
						type: "POST",
						url: "<c:url value="/openapi/addrNumber.do" />",
						dataType: "json",
						async: false,
						data: {
							"text" : dong
						},
						success: function(data){
							var dataTr="<colgroup><col width='70px' /><col width='*' /></colgroup>";
							if(data.addressInfo.length == 0){
								dataTr = "<tfoot><tr><td colspan='2'>데이터가 없습니다.</td></tr></tfoot>";
							}else{
								dataTr += "<tbody>";
								for(var i=0;i<data.addressInfo.length;i++){
									dataTr += "<tr onclick='javascript:goAction(this);'><td>"+data.addressInfo[i][0]+"-"+data.addressInfo[i][1]+"</td><td>"+data.addressInfo[i][2]+"</td></tr>";
								}
								dataTr += "</tbody>";
							}
							$(".listTbl").html(dataTr);
						},
						beforeSend: function(){
						},
						error: function(jqXHR, textStatus, errorThrown){
							//alert(jqXHR.responseText); //에러 페이지 내용
							alert("오류가 발생하였습니다.\n관리자에게 문의 바랍니다.");
						},
						complete: function(){
						}
					 });
				}
			}
			
		</script>
	</head>
	<body>
		<form name="frm" onsubmit="javascript:getAddr();return false;">
			<div>
				<font>동이름</font>
				<input type="text" name="text" maxlength="15" autofocus="autofocus" value="">
				<input type="button" value="검색" onclick="javascript:getAddr();">
			</div>
			<div>
				<table class="listTbl linked" style="width: 400px;">
				</table>
			</div>
		</form>
	</body>
</html>